package com.cheng.spider.custom;

import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;

public abstract class AbstractUrlSource implements UrlSource {

    protected String baseUrl = null;

    protected Queue<String> queue = new ConcurrentLinkedQueue<>();

    public AbstractUrlSource() {
    }

    @Override
    public String getUrl() {
        return baseUrl != null ? baseUrl + queue.poll() : queue.poll();
    }

    @Override
    public boolean isEmpty() {
        return queue.isEmpty();
    }

    public String getBaseUrl() {
        return baseUrl;
    }

    public void setBaseUrl(String baseUrl) {
        this.baseUrl = baseUrl;
    }
}
